/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImagePanel.java
 *
 * Created on 26/07/2011, 8:07:52 PM
 */
package deatax.display.gui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

/**
 *
 * @author Pieman
 */
public class ImagePanel extends javax.swing.JPanel {

    public Image image;
    public int x;
    public int y;
    public int width;
    public int height;
    
    /** Creates new form ImagePanel */
    public ImagePanel() {
        initComponents();
    }
    
    public ImagePanel(Image img) {
        initComponents();
        this.image = img;
        this.x = 0;
        this.y = 0;
        width = image.getWidth(null);
        height = image.getHeight(null);
        this.setPreferredSize(new Dimension(width, height));
    }

    public void setImage(Image image) {
        this.image = image;
        this.x = 0;
        this.y = 0;
        width = image.getWidth(null);
        height = image.getHeight(null);
        this.setPreferredSize(new Dimension(width, height));
    }

    public Image getImage() {
        return image;
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        //System.out.println("drawing to " + x + " " + y + " " + width + " " + height);
        g.drawImage(image, 0, 0, width, height, x, y, x + width, y + height, null);
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
